fix(web): 修复页面切换时 App 样式作用域失效 #31925 - #6042
Open
StrivingRabbit wants to merge 1 commit into
Open
Conversation
Size report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题原因
App.uvue引入的 CSS 经过 scoped 编译后,page选择器会转换为带 App scopeId 的uni-page-body选择器。运行时需要将对应的 scopeId 写入当前页面的
uni-page-body,相关样式及 CSS 变量才能生效。原逻辑通过以下代码全局查找节点:
页面跳转期间,新旧页面的 uni-page-body 可能同时存在。全局查询可能命中离场页面,导致 scopeId 写入错误节点,当前页面无法匹配 App 中定义的 scoped 样式。
因此,该问题本质上不是 CSS 文件加载失败,而是当前页面的 uni-page-body 缺少正确的 scopeId。后续页面显示时如果仍然命中错误节点,CSS 变量也不会自行恢复。
修复方案
修复结论